package com.lyhengtongwl.zqsnews.manage;

import android.util.Log;

import com.lyhengtongwl.zqsnews.entity.NewsNotice;
import com.lyhengtongwl.zqsnews.entity.NewsNoticeEntity;


import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

public class DBManager {
    //批量插入数据
    public static void insert(List<NewsNotice> newsGGS) {
        if (newsGGS != null && newsGGS.size() > 0) {
            for (int i = 0; i < newsGGS.size(); i++) {
                newsGGS.get(i).save();
            }
        }
    }

    //单个插入数据(以对象的格式)
    public static void insertOne(NewsNotice newsGG) {
        Log.e("saveState", "insertOne: "+ newsGG.save());
    }

    //获取所有消息的title
    public static List<String> getNewsTitle() {
        List<String> list = new ArrayList<>();
        List<NewsNotice> newsList = LitePal.findAll(NewsNotice.class);

        for (NewsNotice newsGG : newsList) {
            list.add(newsGG.getTitle());
        }
        return list;
    }

    //获取所有消息
    public static List<NewsNoticeEntity> getAllNews() {
        List<NewsNoticeEntity> list = new ArrayList<>();
        List<NewsNotice> newsList = LitePal.findAll(NewsNotice.class);
        for (NewsNotice newsGG : newsList) {
            NewsNoticeEntity notice=new NewsNoticeEntity();
            notice.setContent(newsGG.getContent());
            notice.setTime(newsGG.getTime());
            notice.setTitle(newsGG.getTitle());
            list.add(notice);
        }
        return list;
    }
}
